<?php
use yii\helpers\Url;
$this->context->layout = false;
?>
<?php
//使用率
echo $this->render("@app/views/public/useRate.php")
?>
<div id="Personal-List"></div>
<script type="text/x-kendo-template" id="personalTemplate">
	<a class="k-button k-button-icontext" onclick="onpersonalEarlyTime()"><span class="glyphicon glyphicon-list-alt"></span> 早班时间<?php if(!empty($remind['EarlyTimeNumber'])&&$remind['EarlyTimeNumber']!=0)echo "<span class='badge remind-back-color'>$remind[EarlyTimeNumber]</span>"?></a>
	<input type="text" id="psl_date_month"  name="psl_date_month" value="<?=$data?>" placeholder="月份">
	<span id="personalDeductions"></span>
</script>
<script>
	var Personal_grid = $("#Personal-List");
	$(document).ready(function() {
		Personal_grid.kendoGrid({
			dataSource: {
				transport: {
					read:function (e) {
						$.ajax({
							url: "<?=Url::to(['personallist','psl_date_month'=>'']); ?>"+$("#psl_date_month").val(),
							dataType: "json",
							success:function (redata) {
								e.success(redata);
								getDeductions();
							}
						})
					}
				},
				schema: {
					model: {
						id:"id",
						fields: {
							id: { field:"id" ,editable: false, nullable: true },
							created: { field:"created",type:"date"},
							content: { field:"content"},
							rating_name: { field:"rating_name"},
							rating_points: { field:"rating_points"},
							deductions_situation: {field:"deductions_situation"},
							early_number: {field:"early_number"}
						}
					}
				},
				pageSize: 20
			},
			filterable: {
                extra: false,
                operators: {
                    string: {
                        contains: "包含",
                        doesnotcontain: "不包含",
                        eq: "等于",
                        neq: "不等于"
                    }
                }
            },
			sortable: true,
			// reorderable: true,
			// resizable: true,
			// columnMenu: true,
			toolbar:kendo.template($("#personalTemplate").html()),
			pageable:{
					refresh: true,//刷新按钮
					pageSizes: [20, 40, 60, "all"],//每页数量选择
					buttonCount: 5//页码按钮数量
			},
			columns: [
				{
					field:"created",
					title: "发布日期(美国时间)" ,
					format: "{0:MM/dd/yyyy HH:mm}",
					headerAttributes: alignCenterAttribute,
					attributes: alignCenterAttribute
				},
				{
					field: "content",
					title:"详细內容" ,
					template: function(e){
						var str = e.content,len = 20;
						if(str.length <= len) {
							return str;
						}
						var strlen = 0;
						var s = "";
						for(var i = 0;i < str.length; i++) {
							s = s + str.charAt(i);
							if (str.charCodeAt(i) > 128) {
								strlen = strlen + 2;
								if(strlen >= len){
									return "<span title='"+e.content+"'>"+s.substring(0,s.length-1) + "…</span>";
								}
							} else {
								strlen = strlen + 1;
								if(strlen >= len){
									return "<span title='"+e.content+"'>"+s.substring(0,s.length-2) + "…</span>";
								}
							}
						}
						return "<span title='"+e.content+"'>"+s+"</span>";
					},
					headerAttributes: alignCenterAttribute,
					attributes: alignCenterAttribute
				},
				{
					field: "rating_name",
					title:"评级" ,
					headerAttributes: alignCenterAttribute,
					attributes: alignCenterAttribute
				},
				{
					field: "rating_points",
					title:"扣分情况",
					template:"#if(rating_points ==null){#0分/次#}else{##= rating_points #分/次#}#",
					headerAttributes: alignCenterAttribute,
					attributes: alignCenterAttribute
				},
				{
					field:"deductions_situation",
					title: "扣款金额",
					template:function(e){
            if(e.rating_open==0){
                return "0元";
            }
						if(e.deductions_situation ==null)
						{
							$str = "0元";
						}else{
							$str = e.deductions_situation+" 元";
						}
						return $str;
					},
					headerAttributes: alignCenterAttribute,
					attributes: alignCenterAttribute
				},
				{
					field: "early_number",
					title:"早班次数" ,
					template:function (e) {
						if(e.early_number ==null){
							if (e.punishment_standard==1){
								return "0次 首";
							}else{
								return "0次"
							}
						}else{
							if (e.punishment_standard==1){
								return e.early_number+"次 首";
							}else{
								return e.early_number+"次"
							}
						}
					},
					headerAttributes: alignCenterAttribute,
					attributes: alignCenterAttribute
				}
			],

		});
		$("#psl_date_month").kendoDatePicker({
			start: "year",
			depth: "year",
			format: "yyyy/MM",
			change:function(e){
				var __grid = Personal_grid.data("kendoGrid");
				__grid.dataSource.read();
				__grid.refresh();
			}
		});
	});

	function onpersonalEarlyTime(){
		if (!ModifyTimeWindow.data("kendoWindow")) {
			ModifyTimeWindow.kendoWindow({
				width: "800",
				height:"400",
				title: "早班列表",
				actions: [
					"Close"
				],
				position:{
					left:"30%",
					top:"27%",
				}
			}).data("kendoWindow");
		}
		ModifyTimeWindow.data("kendoWindow").refresh({
			url: "<?=Url::to(['personalearlytime']) ?>"
		});
		ModifyTimeWindow.data("kendoWindow").open();
	}
	function getDeductions() {
			$.ajax({
				url: "<?=Url::to(['getdeductions','psl_date_month'=>'']); ?>"+$("#psl_date_month").val(),
				type: 'get',
				dataType: 'json',
				success: function (res) {
					$("#personalDeductions").text("本月扣款总额"+res+"元");
				}
			})
	}
</script>
